<template>
  <div class="VolunteerDetails">
    <div class="VolunteerDetails_boxtop">
      <div class="VolunteerDetails_top">
        <div class="VolunteerDetails_top_box">
          <router-link to="/">
            <img
              class="VolunteerDetails_top_logo"
              src="https://huizeimg.oss-cn-shenzhen.aliyuncs.com/huize/update/156222927235720190704163413.jpg"
              alt
            />
          </router-link>
          <div class="VolunteerDetails_top_content">志愿详情</div>
        </div>
      </div>
    </div>
    <div class="VolunteerDetails_bottom">
      <div class="VolunteerDetails_boxbottom">
        <div class="VolunteerDetails_bottom_option">
          <router-link to="/" class="router">
            <span>首页</span>
          </router-link>
          <span>></span>
          <router-link to="/Intelligence" v-show="toshow==1" class="router">
            <span>填报志愿</span>
          </router-link>
          <router-link to="/VolunteerList" v-show="toshow==2" class="router">
            <span>个人中心</span>
          </router-link>
          <span>></span>  
          <span v-show="toshow==1">填报</span>
          <span v-show="toshow==2">填报</span>
        </div>
        <div class="VolunteerDetails_bottom_form">
          <div class="my_form">
            我的志愿表 {{
            this.$route.params.schoolId == 'NaN' ? volunteerNameinput : VolunteerDetailsList.volunteerName
            }}
          </div>
          <div class="my_time">{{VolunteerDetailsList.createTime}}</div>
          <div class="my_input">
            修改志愿表名称
            <el-input
              placeholder="请输入内容"
              v-model="volunteerNameinput"
              :disabled="!show"
              v-if="this.$route.params.schoolId == 'NaN'"
            ></el-input>
            <el-input
              v-else
              placeholder="请输入内容"
              v-model="VolunteerDetailsList.volunteerName"
              :disabled="!show"
            ></el-input>
          </div>
          <div class="deit">
            <el-button type="info" @click="change" v-if="show">编辑</el-button>
            <el-button type="primary" @click="change" v-else>编辑</el-button>

            <!-- <el-button type="warning" @click="addVolunteer()" v-if="show">确定修改</el-button> -->
            <el-button type="warning" @click="openLogin" v-if="show">确定保存</el-button>
            <el-button type="warning" disabled v-else>确定保存</el-button>
          </div>

          <!-- <div class="my_lvse">
            <div class="my_lvse_content">
              合理性 非常好、点击查看完整的分析报告
              <span class="el-icon-arrow-right"></span>
            </div>
          </div>-->
        </div>
        <div class="title_benke">{{U.batchName}}</div>
        <div class="VolunteerDetails_bottom_benke">
          <div class="VolunteerDetails_bottom_benke_line">
            <div class="University1">
              <div class="add_school" v-if="!show">
                <div class="add_school_Tips">请先点击编辑</div>
              </div>
              <div class="addschool">继续添加学校</div>
              <div class="choose_school" @click="addSchoolsU">
                选择院校
                <span class="el-icon-arrow-right"></span>
              </div>
              <div class="volunteer_add" @click="addMySchoolsU">
                从备选志愿里添加
                <span class="el-icon-arrow-right"></span>
              </div>
            </div>
            <div class="University" v-for=" (tiem , index  )  in schoolList.U" :key="tiem.id">
              <router-link
                :to="{

              name:'/SchoolDeatil',
              params:{
                userId:tiem.schoolId
              }
            }"
                v-if="!show"
                class="goSchool"
                tag="div"
              ></router-link>

              <div class="line_one">
                <img class="school_logo" :src="tiem.logoUrl" alt />
                <div class="school_name">{{tiem.schoolName}}</div>
                <i class="el-icon-delete" @click="cutSchool(tiem ,index)" v-if="show"></i>
              </div>
              <div class="school_city">{{tiem.uniCity}}</div>
              <div
                class="major"
                v-for="(majorList,majorIndex ) in tiem.majorAllEntities"
                :key="majorList.majorAllId"
              >
                <span>
                  {{majorIndex+1}}、
                  {{majorList.category}}
                </span>
                <i
                  class="el-icon-close"
                  v-show="show"
                  @click="cutMajor(tiem, majorList.majorAllId,index ,majorIndex )"
                ></i>
              </div>
              <div v-if="show">
                <div
                  @click="addMajor(tiem.schoolId ,tiem,tiem.schoolName ,index)"
                  class="majorlan"
                  v-if="tiem.majorAllEntities.length < Undergraduate.majorNumber+1"
                >
                  继续添加专业
                  <span class="el-icon-arrow-right"></span>
                </div>
              </div>

              <div class="listindex">{{String.fromCharCode(64 + parseInt(index+1))}}</div>
            </div>
            <div class="major1"></div>
            <div class="major1"></div>
          </div>
        </div>
        <div class="title_benke">{{S.batchName}}</div>
        <div class="VolunteerDetails_bottom_benke">
          <div class="VolunteerDetails_bottom_benke_line">
            <div class="University1">
              <div class="add_school" v-if="!show">
                <div class="add_school_Tips">请先点击编辑</div>
              </div>
              <div class="addschool">继续添加学校</div>
              <div class="choose_school" @click="addSchoolsS">
                选择院校
                <span class="el-icon-arrow-right"></span>
              </div>
              <div class="volunteer_add" @click="addMySchoolsS">
                从备选志愿里添加
                <span class="el-icon-arrow-right"></span>
              </div>
            </div>
            <div class="University" v-for="(tiem , index) in schoolList.S" :key="tiem.schoolId">
              <router-link
                :to="{

              name:'/SchoolDeatil',
              params:{
                userId:tiem.schoolId
              }
            }"
                v-if="!show"
                class="goSchool"
                tag="div"
              ></router-link>
              <div class="line_one">
                <img class="school_logo" :src="tiem.logoUrl" alt />
                <div class="school_name">{{tiem.schoolName}}</div>
                <i class="el-icon-delete" @click="cutSchool(tiem ,index)" v-if="show"></i>
              </div>
              <div class="school_city">{{tiem.uniCity}}</div>
              <div
                class="major"
                v-for="(majorList,majorIndex ) in tiem.majorAllEntities"
                :key="majorList.majorAllId"
              >
                <span>
                  {{majorIndex+1}}、
                  {{majorList.category}}
                </span>
                <i
                  class="el-icon-close"
                  v-show="show"
                  @click="cutMajor(tiem, majorList.majorAllId,index ,majorIndex )"
                ></i>
              </div>
              <div v-if="show">
                <div
                  @click="addMajor(tiem.schoolId ,tiem ,tiem.schoolName ,index)"
                  class="majorlan"
                  v-if="tiem.majorAllEntities.length < Undergraduate.majorNumber+1"
                >
                  继续添加专业
                  <span class="el-icon-arrow-right"></span>
                </div>
              </div>

              <div class="listindex">{{String.fromCharCode(64 + parseInt(index+1))}}</div>
            </div>
            <div class="major1"></div>
            <div class="major1"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="Write" v-if="WriteType ==  1 ">
      <div class="Write_major">
        <div class="name_lists_header">
          <div class="Choose_Major">
            <i class="el-icon-close" @click="cutMajorList()"></i>
            <span>请将您想上的专业添加入列表</span>
            <div @click="AddMajorAllId">完成</div>
          </div>
        </div>
        <div class="schools_name">{{schoolName}}</div>
        <div class="name_lists_bottom">
          <div class="lists_bottom">
            <ul>
              <li v-for=" (list  , index) in majorList" :key="index">
                <div class="lists_bottom_left">
                  <h3>{{list.majIntroduce}}</h3>
                  <div class="lists_bottom_left_bottom">
                    <p>
                      18年录取最低排名
                      <span>{{list.minRanking != '' ? list.minRanking : "null" }}</span>
                    </p>
                    <p>
                      18年招生人数
                      <span>{{list.planNum != '' ? list.planNum : "null"}}</span>
                    </p>
                    <p>
                      18年录取最低分
                      <span>{{list.minScore != '' ? list.minScore : "null"}}</span>
                    </p>
                  </div>
                </div>
                <div class="lists_bottom_button">
                  <el-button
                    type="primary"
                    v-if="majorAllIds.indexOf(list.majorAllId  ) == -1  "
                    @click="addMjaorID(list.majorAllId,index, list ) "
                  >
                    <i class="el-icon-plus"></i> 更多专业
                  </el-button>

                  <el-popover
                    v-else
                    placement="bottom"
                    title="提示"
                    width="200"
                    trigger="click"
                    content="该选项以被选择了。 请重新选择其它选项"
                  >
                    <el-button type="warning" slot="reference">
                      <i class="el-icon-check"></i> 已加专业
                    </el-button>
                  </el-popover>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
    <div class="Write" v-if="WriteType ==  2 ">
      <div class="Write_major">
        <div class="name_lists_header">
          <div class="Choose_Major">
            <i class="el-icon-close" @click="cutMajorList()"></i>
            <span>请将您想上的学校添加到学校列表</span>
          </div>
        </div>
        <div class="schools_name">猜你喜欢</div>
        <div class="name_lists_bottom">
          <div class="lists_bottom">
            <ul v-infinite-scroll="load" infinite-scroll-disabled="disabled">
              <span v-if="schoolType == 0">
                <li
                  v-for=" (list  , index) in school.schoolAll.list"
                  :key="index"
                  v-show="   list.batch == U.id"
                >
                  <div class="lists_bottom_left school_list">
                    <img :src="list.logoUrl" alt />
                    <h3>
                      {{list.schoolName}}
                      <h5>{{list.uniCity}}</h5>
                    </h3>
                  </div>
                  <div class="lists_bottom_button">
                    <el-button
                      type="primary"
                      v-if="schoolIdlist.indexOf( parseInt(list.schoolId) ) == -1  "
                      @click="addSchoolID(list.schoolId , list  ) "
                    >
                      <i class="el-icon-plus"></i> 添加院校
                    </el-button>

                    <el-popover
                      v-else
                      placement="bottom"
                      title="提示"
                      width="200"
                      trigger="click"
                      content="该学校已被选择了。 请重新选择其它学校"
                    >
                      <el-button type="warning" slot="reference">
                        <i class="el-icon-check"></i> 添加院校
                      </el-button>
                    </el-popover>
                  </div>
                </li>
              </span>
              <span v-else>
                <li
                  v-for=" (list  , index) in school.schoolAll.list"
                  :key="list.schoolId +index"
                  v-show="   list.batch == S.id"
                >
                  <div class="lists_bottom_left school_list">
                    <img :src="list.logoUrl" alt />
                    <h3>
                      {{list.schoolName}}
                      <h5>{{list.uniCity}}</h5>
                    </h3>
                  </div>
                  <div class="lists_bottom_button">
                    <el-button
                      type="primary"
                      v-if="schoolIdlist.indexOf( parseInt(list.schoolId) ) == -1  "
                      @click="addSchoolID(list.schoolId , list  ) "
                    >
                      <i class="el-icon-plus"></i> 添加院校
                    </el-button>

                    <el-popover
                      v-else
                      placement="bottom"
                      title="提示"
                      width="200"
                      trigger="click"
                      content="该选项以被选择了。 请重新选择其它学校"
                    >
                      <el-button type="warning" slot="reference">
                        <i class="el-icon-check"></i> 添加院校
                      </el-button>
                    </el-popover>
                  </div>
                </li>
              </span>
            </ul>
            <p v-if="loading">加载中...</p>
            <p v-if="noMore">没有更多了</p>
          </div>
        </div>
      </div>
    </div>
    <div class="Write" v-if="WriteType ==  3">
      <div class="Write_major">
        <div class="name_lists_header">
          <div class="Choose_Major">
            <i class="el-icon-close" @click="cutMajorList()"></i>
            <span>请将您想上的学校添加到列表</span>
            <div @click="AddSchoolAllId">完成</div>
          </div>
        </div>
        <div class="schools_name">备选志愿</div>
        <div class="name_lists_bottom">
          <div class="lists_bottom_new">
            <ul>
              <li v-for="(tiem , index) in MyAlternativeList" :key="tiem.schoolId">
                <div class="lists_new_header">
                  <div class="header_school_new">
                    <img :src="tiem.logoUrl" alt />
                    <div class="header_school_new_right">
                      <h3>{{tiem.schoolName}}</h3>
                      <h4>{{tiem.uniCity}}</h4>
                    </div>
                  </div>
                  <div class="meader_shool_new_numder">
                    <ul>
                      <li>
                        {{tiem.year - 1}} 年录取最低分
                        <span>{{tiem.minScore}}</span>
                      </li>
                      <li>
                        {{tiem.year - 1}} 年录取数
                        <span>{{tiem.deliveryNum}}</span>
                      </li>
                      <li>
                        {{tiem.year - 1}} 年录取最低排名
                        <span>{{tiem.minRanking}}</span>
                      </li>
                    </ul>
                  </div>
                </div>
                <div class="lists_new_major">
                  <ul>
                    <li v-for=" (major , Index ) in tiem.subjectVoList" :key="major.majorAllId">
                      <div class="lists_new_majorName">
                        <span v-if="NewSchoolIdList.indexOf(parseInt(tiem.schoolId) )  == -1">
                          <i
                            class="icon-plus"
                            v-if="MajorIdLIsts.indexOf(parseInt(major.majorAllId) )  == -1"
                            @click="addSchoolMajor(major,tiem ,index ,Index )"
                          ></i>

                          <i
                            class="el-icon-circle-check"
                            v-else
                            @click="cutSchoolMajor(major.majorAllId ,index ,Index)"
                          ></i>
                        </span>
                        <span v-else>
                          <el-popover
                            placement="bottom"
                            title="提示"
                            width="200"
                            trigger="click"
                            content="该学校已被选择了。 请重新选择其它学校"
                          >
                            <i class="el-icon-circle-check" slot="reference"></i>
                            已加学校
                          </el-popover>
                        </span>
                        {{major.category}}
                      </div>
                      <div class="lists_new_majorNumder">
                        <ul>
                          <li>
                            {{tiem.year - 1}} 年录取最低分
                            <span>{{major.minScore}}</span>
                          </li>
                          <li>
                            {{tiem.year - 1}} 年录取数
                            <span>{{major.admissionNum}}</span>
                          </li>
                          <li>
                            {{tiem.year - 1}} 年录取最低排名
                            <span>{{major.minRanking}}</span>
                          </li>
                        </ul>
                      </div>
                    </li>
                  </ul>
                </div>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "VolunteerDetails",
  data() {
    return {
      toshow:'',
      visible: false,
      show: false,
      Ishow: false,
      VolunteerDetailsList: "",
      volunteerNameinput: "",
      Specialty: "",
      Undergraduate: "",
      WriteType: 0,
      majorList: "",
      majorAllIds: [],
      schoolName: "",
      majorIDs: "",
      schoolIndex: "",
      U: "",
      U1:"",
      U2:"",
      S: "",
      Undergraduate: "",
      Specialty: "",
      schoolNumType: "",
      majorListArr: [],
      school: {
        schoolAll: "",
        pageNows: 1,
        pageSize: 0
      },
      MyAlternativeList: "",
      schoolIdlist: "",
      loading: false,
      checkList: [],
      schoolMajorLists: [],
      MajorIdLIsts: [],
      NewSchoolIdList: [],
      schoolType: "",
      schoolList: {
        U: [],
        S: []
      },
      BatchType: ""
    };
  },
  computed: {
    noMore() {
      return this.school.pageSize >= this.school.schoolAll.totalCount;
    },
    disabled() {
      return this.loading || this.noMore;
    }
  },
  methods: {
    openFullScreen() {
      const loading = this.$loading({
        lock: true,
        text: "正在保存数据",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      setTimeout(() => {
        loading.close();
      }, 3000);
    },
    open3(s) {
      this.$message.error(s);
    },
    change() {
      this.show = !this.show;
    },
    cutMajorList() {
      this.WriteType = "";
      this.majorListArr = [];
      this.majorAllIds = [];
    },
    //  获取已添加学校列表
    getVolunteerDetails() {
      this.$ajax({
        method: "POST",
        url: "/api/volunteer/volunteer/info?id=" + this.$route.params.schoolId,

        success: res => {
          if (res.data.code == 0) {
            this.VolunteerDetailsList = res.data.data;

            this.cutPart();
          } else {
            this.open3(res.data.msg);
          }
        }
      });
    },
    cutPart() {
      this.VolunteerDetailsList.volunteerSchoolEntity.map(d => {
        if (d.batch == this.U.id) {
          this.schoolList.U.push(d);
        } else if (d.batch == this.S.id) {
          this.schoolList.S.push(d);
        }
      });
    },
    cutSchool(arr, index) {
      if (arr.batch == this.U.id) {
        var arrList = this.schoolList.U;
        arrList.splice(index, 1);
      } else if (arr.batch == this.S.id) {
        var arrList = this.schoolList.S;
        arrList.splice(index, 1);
      }
    },
    cutMajor(majorList, ID, index, major) {
      console.log(majorList, index);
      if (majorList.batch == this.U.id) {
        var arrList = this.schoolList.U;
        arrList.splice(index, 1);

        majorList.majorAllEntities.splice(major, 1);

        majorList.majorAllIds = majorList.majorAllIds.replace(ID, "");

        this.schoolList.U.splice(index, 0, majorList);
      } else if (majorList.batch == this.S.id) {
        var arrList = this.schoolList.S;
        arrList.splice(index, 1);

        majorList.majorAllEntities.splice(major, 1);

        majorList.majorAllIds = majorList.majorAllIds.replace(ID, "");

        this.schoolList.S.splice(index, 0, majorList);
      }
    },
    //是否保存
    openLogin() {
      if (this.$route.params.schoolId == "NaN") {
        this.$confirm("此操作会修改志愿表, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            this.addVolunteer();
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消修改"
            });
          });
      } else {
        this.$confirm("此操作会修改志愿表, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            this.modify();
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消修改"
            });
          });
      }
    },
    //手动填报
    addVolunteer() {
      this.openFullScreen();

      var U = [];
      this.schoolList.U.map((u, index) => {
        if (u.majorAllEntities.length == 0) {
          U.push(u.schoolName);
          return U;
        }
      });
      this.schoolList.S.map((s, index) => {
        if (s.majorAllEntities.length == 0) {
          console.log(s);
          U.push(s.schoolName);
          return U;
        }
      });
      console.log(U);
      if (this.volunteerNameinput == "") {
        this.open3("请输入表单名称");
      } else {
        if (U.length == 0) {
          this.show = false;

          var arrs = [];

          this.schoolList.U.map(u => {
            arrs.push(u);
          });
          this.schoolList.S.map(s => {
            arrs.push(s);
          });

          var lists = arrs.map((item, index, ary) => {
            console.log(item, index, ary);
            var schoolIds = item.schoolId;

            var majorAllIds = item.majorAllEntities.map(
              (items, indexs, arys) => {
                var ID = items.majorAllId;
                return ID;
              }
            );

            var newMajorAllIds = majorAllIds.join();
            var NewMajorAllIds = newMajorAllIds.replace(/\[.*?\]/g, "");

            return {
              schoolId: parseInt(schoolIds),
              batch: item.batch,
              majorAllIds: NewMajorAllIds
            };
          });

          this.$ajax({
            method: "POST",

            url: "/api/volunteer/save/volunteer",

            data: {
              alternativeType: 3,
              volunteerId: 0,
              volunteerName: this.volunteerNameinput,
              volunteerSchoolEntities: lists
            },
            success: res => {
              if (res.data.code == 0) {
                this.$message({
                  type: "success",
                  message: "修改成功!"
                });
                router.push(this.$route.fullPath);
                this.show = false;
              } else {
                this.open3(res.data.msg);
              }
            }
          });
        } else {
          this.open3(" “ " + U + " ” " + "专业不能为空");
        }
      }
    },
    //修改保存志愿
    modify() {
      this.openFullScreen();

      var U = [];
      this.schoolList.U.map((u, index) => {
        if (u.majorAllEntities.length == 0) {
          U.push(u.schoolName);
          return U;
        }
      });
      this.schoolList.S.map((s, index) => {
        if (s.majorAllEntities.length == 0) {
          console.log(s);
          U.push(s.schoolName);
          return U;
        }
      });
      // 判断专业是否为空
      if (U.length == 0) {
        this.VolunteerDetailsList.volunteerSchoolEntity = [];
        if (this.VolunteerDetailsList.volunteerSchoolEntity.length == 0) {
          this.schoolList.U.map(u => {
            this.VolunteerDetailsList.volunteerSchoolEntity.push(u);
          });
          this.schoolList.S.map(s => {
            this.VolunteerDetailsList.volunteerSchoolEntity.push(s);
          });
        }

        var arr = this.VolunteerDetailsList.volunteerSchoolEntity.map(function(
          tiem
        ) {
          return {
            batch: tiem.batch,
            majorAllIds: tiem.majorAllIds,
            schoolId: tiem.schoolId,
            volunteerFormId: tiem.id
          };
        });

        this.$ajax({
          method: "POST",

          url: "/api/volunteer/update/volunteer",
          data: {
            alternativeType: this.VolunteerDetailsList.volunteerType,
            volunteerId: this.VolunteerDetailsList.id,
            volunteerName: this.VolunteerDetailsList.volunteerName,
            volunteerSchoolEntities: arr
          },
          success: res => {
            if (res.data.code == 0) {
              router.push(this.$route.fullPath);
              this.show = false;
              this.$message({
                type: "success",
                message: "修改成功!"
              });
            } else {
              this.open3(res.data.msg);
            }
          }
        });
      } else {
        this.open3(" “ " + U + " ” " + "专业不能为空");
      }
    },

    //继续添加专业
    addMajor(ID, majors, name, index) {
      this.schoolNumType = true;
      this.WriteType = 1;
      this.schoolName = name;
      if (majors.batch == this.U.id) {
        this.schoolIndex = {
          indexs: index,
          batch: this.U.id
        };
      } else if (majors.batch == this.S.id) {
        this.schoolIndex = {
          indexs: index,
          batch: this.S.id
        };
      }

      this.majorAllIds = majors.majorAllIds;

      this.$ajax({
        method: "GET",
        url: "/api/volunteer/voluntaryTest1/" + ID,

        success: res => {
          if (res.data.code == 0) {
            this.majorList = res.data.data;
          }
        }
      });
    },
    //添加专业
    addMjaorID(id, index, obj) {
      if (this.schoolNumType) {
        if (this.schoolIndex.batch == this.U.id) {
          if (
            this.Undergraduate.majorNumber >
            this.schoolList.U[this.schoolIndex.indexs].majorAllEntities.length +
              this.majorListArr.length
          ) {
            var str = this.majorAllIds + "," + id;
            this.majorAllIds = str;

            var addMajor = {
              category: obj.majIntroduce,
              majorAllId: obj.majorAllId
            };

            this.majorListArr.push(addMajor);
          } else {
            alert("不能超过" + this.Undergraduate.majorNumber);
          }
        } else if (this.schoolIndex.batch == this.S.id) {
          if (
            this.Specialty.majorNumber >
            this.schoolList.S[this.schoolIndex.indexs].majorAllEntities.length +
              this.majorListArr.length
          ) {
            var str = this.majorAllIds + "," + id;
            this.majorAllIds = str;

            var addMajor = {
              category: obj.majIntroduce,
              majorAllId: obj.majorAllId
            };

            this.majorListArr.push(addMajor);
          } else {
            alert("不能超过" + this.Specialty.majorNumber);
          }
        }
      }
    },
    //完成添加专业
    AddMajorAllId() {
      if (this.schoolIndex.batch == this.U.id) {
        this.schoolList.U[
          this.schoolIndex.indexs
        ].majorAllIds = this.majorAllIds;
        this.majorListArr.map(e => {
          this.schoolList.U[this.schoolIndex.indexs].majorAllEntities.push(e);
        });
      } else if (this.schoolIndex.batch == this.S.id) {
        this.schoolList.S[
          this.schoolIndex.indexs
        ].majorAllIds = this.majorAllIds;
        this.majorListArr.map(e => {
          this.schoolList.S[this.schoolIndex.indexs].majorAllEntities.push(e);
        });
      }

      this.WriteType = "";
      this.majorListArr = [];
      this.majorAllIds = [];
    },
    cutMjaorID(id) {
      var index = this.majorAllIds.indexOf(toString(id));

      this.majorAllIds.filter(toString(id), 1);
      var arr = [id];

      var majorIndex = this.VolunteerDetailsList.volunteerSchoolEntity[
        this.schoolIndex
      ].majorAllEntities;

      var finalArr = majorIndex.filter(item => !arr.includes(item.majorAllId));
      this.VolunteerDetailsList.volunteerSchoolEntity[
        this.schoolIndex
      ].majorAllEntities = finalArr;
    },
    // 获取批次
    getBatch() {
      this.$ajax({
        method: "POST",
        url: "/api/voluntary/targetBatch",

        success: res => {
          if (res.data.code == 0) {
            var Batch = res.data.data.suitableBatch;
            var s = [];
             this.BatchList = 
            Batch.forEach(e => {
              s.push(e);
              return s;
            });
            this.U = s[0];
            this.S = s[1];
           

            this.getMajorNum();
            if (this.$route.params.schoolId == "NaN") {
              this.show = true;
            } else {
              this.getVolunteerDetails();
            }
          } else {
            this.open3(res.data.msg);
          }
        }
      });
    },
    getMajorNum() {
      this.$ajax({
        method: "GET",
        url: "/api/volunteerNum/schoolNum/" + this.U.id,

        success: res => {
          if (res.data.code == 0) {
            this.Undergraduate = res.data.data;
          }
        }
      });
      this.$ajax({
        method: "GET",
        url: "/api/volunteerNum/schoolNum/" + this.S.id,

        success: res => {
          if (res.data.code == 0) {
            this.Specialty = res.data.data;
          }
        }
      });
    },
    //选择添加学校
    addSchoolsU() {
      this.WriteType = 2;
      this.schoolType = 0;

      if (this.$route.params.schoolId == "NaN") {
        var U = [];
        this.schoolList.U.map(u => {
          U.push(parseInt(u.schoolId));
        });
        this.schoolIdlist = U;
      } else {
        var schoolId = this.VolunteerDetailsList.volunteerSchoolEntity;
        var S = [];
        schoolId.map(j => {
          S.push(parseInt(j.schoolId));
        });
        this.schoolIdlist = S;
      }

      this.$ajax({
        method: "POST",
        url: "/api/volunteer/select/schoolAll",
        data: {
          batch: this.U.id,
          pageNow: this.school.pageNows,
          pageSize: 10 + this.school.pageSize
        },

        success: res => {
          if (res.data.code == 0) {
            this.school.schoolAll = res.data.data;
          }
        }
      });
    },
    //选择添加学校
    addSchoolsS() {
      this.WriteType = 2;
      this.schoolType = 1;
      if (this.$route.params.schoolId == "NaN") {
        var S = [];
        this.schoolList.S.map(s => {
          S.push(parseInt(s.schoolId));
        });
        this.schoolIdlist = S;
      } else {
        var schoolId = this.VolunteerDetailsList.volunteerSchoolEntity;
        var S = [];
        schoolId.map(j => {
          S.push(parseInt(j.schoolId));
        });
        this.schoolIdlist = S;
      }

      this.$ajax({
        method: "POST",
        url: "/api/volunteer/select/schoolAll",
        data: {
          batch: this.S.id,
          pageNow: this.school.pageNows,
          pageSize: 10 + this.school.pageSize
        },

        success: res => {
          if (res.data.code == 0) {
            this.school.schoolAll = res.data.data;
          }
        }
      });
    },
    //我的备选添加学校(专科)
    addMySchoolsS() {
      this.BatchType = this.S.id;
      this.WriteType = 3;
      if (this.$route.params.schoolId == "NaN") {
      } else {
        this.VolunteerDetailsList.volunteerSchoolEntity.map(id => {
          this.NewSchoolIdList.push(id.schoolId);
        });
      }

      this.$ajax({
        method: "POST",
        url: "/api/volunteer/voluntaryTest?batch=" + this.S.id,

        success: res => {
          if (res.data.code == 0) {
            this.MyAlternativeList = res.data.data;
            var arr = this.MyAlternativeList;

            arr.map(i => {
              var arrNew = {
                logoUrl: i.logoUrl,
                schoolName: i.schoolName,
                schoolId: i.schoolId,
                uniCity: i.uniCity,
                majorAllEntities: []
              };
              this.schoolMajorLists.push(arrNew);
            });
          }
        }
      });
    },
    //我的备选添加学校(本科)
    addMySchoolsU() {
      this.BatchType = this.U.id;
      this.WriteType = 3;
      if (this.$route.params.schoolId == "NaN") {
      } else {
        this.VolunteerDetailsList.volunteerSchoolEntity.map(id => {
          this.NewSchoolIdList.push(id.schoolId);
        });
      }

      this.$ajax({
        method: "POST",
        url: "/api/volunteer/voluntaryTest?batch=" + this.U.id,

        success: res => {
          if (res.data.code == 0) {
            this.MyAlternativeList = res.data.data;
            var arr = this.MyAlternativeList;

            arr.map(i => {
              var arrNew = {
                logoUrl: i.logoUrl,
                schoolName: i.schoolName,
                schoolId: i.schoolId,
                uniCity: i.uniCity,
                majorAllEntities: []
              };
              this.schoolMajorLists.push(arrNew);
            });
          }
        }
      });
    },
    //完成 我的备选添加学校
    AddSchoolAllId() {
      this.schoolMajorLists.map(s => {
        if (s.majorAllEntities.length > 0) {
          var num = [];
          s.majorAllEntities.map(i => {
            num.push(i.majorAllId);

            return num;
          });

          let majorID = String(num);

          var Arr = {
            batch: this.BatchType,
            majorAllIds: majorID,
            majorAllEntities: s.majorAllEntities,
            logoUrl: s.logoUrl,
            schoolName: s.schoolName,
            schoolId: s.schoolId,
            uniCity: s.uniCity
          };

          if (this.BatchType == this.U.id) {
            this.schoolList.U.push(Arr);
            this.schoolMajorLists = [];
          } else if (this.BatchType == this.S.id) {
            this.schoolList.S.push(Arr);
            this.schoolMajorLists = [];
          }
        }
      });
      this.WriteType = "";
    },
    //下拉获取更多学校
    load() {
      this.loading = true;
      setTimeout(() => {
        this.school.pageSize += 10;

        this.loading = false;
        if (this.schoolType == 0) {
          this.$ajax({
            method: "POST",
            url: "/api/volunteer/select/schoolAll",
            data: {
              batch: this.U.id,
              pageNow: this.school.pageNows,
              pageSize: 10 + this.school.pageSize
            },

            success: res => {
              if (res.data.code == 0) {
                this.school.schoolAll = res.data.data;
              }
            }
          });
        } else {
          this.$ajax({
            method: "POST",
            url: "/api/volunteer/select/schoolAll",
            data: {
              batch: this.S.id,
              pageNow: this.school.pageNows,
              pageSize: 10 + this.school.pageSize
            },

            success: res => {
              if (res.data.code == 0) {
                this.school.schoolAll = res.data.data;
              }
            }
          });
        }
      }, 4000);
    },
    // 添加更多学校
    addSchoolID(ID, arr) {
      if (arr.batch == this.U.id) {
        if (this.Undergraduate.schoolNumber > this.schoolList.U.length) {
          if (this.$route.params.schoolId == "NaN") {
            var arrNew = [];
            arrNew.push(arr);
            arrNew.map(e => {
              var str = {
                batch: e.batch,
                logoUrl: e.logoUrl,
                schoolId: e.schoolId,
                schoolName: e.schoolName,
                uniCity: e.uniCity,
                majorAllIds: "",
                majorAllEntities: []
              };
              this.schoolList.U.push(str);

              this.WriteType = "";
            });
          } else {
            var schoolId = this.VolunteerDetailsList.volunteerSchoolEntity;
            var S = [];
            schoolId.map(j => {
              S.push(parseInt(j.schoolId));
            });
            if (S.indexOf(parseInt(ID)) == -1) {
              var arrNew = [];
              arrNew.push(arr);
              arrNew.map(e => {
                var str = {
                  batch: e.batch,
                  logoUrl: e.logoUrl,
                  schoolId: e.schoolId,
                  schoolName: e.schoolName,
                  uniCity: e.uniCity,
                  majorAllIds: "",
                  majorAllEntities: []
                };
                this.schoolList.U.push(str);
                this.VolunteerDetailsList.volunteerSchoolEntity.push(str);
                this.WriteType = "";
              });
            } else {
              this.WriteType = "";
            }
          }
        } else {
          alert("不能超过" + this.Undergraduate.schoolNumber + "加学校");
        }
      } else if (arr.batch == this.S.id) {
        if (this.Undergraduate.schoolNumber > this.schoolList.S.length) {
          if (this.$route.params.schoolId == "NaN") {
            var arrNew = [];
            arrNew.push(arr);
            arrNew.map(e => {
              var str = {
                batch: e.batch,
                logoUrl: e.logoUrl,
                schoolId: e.schoolId,
                schoolName: e.schoolName,
                uniCity: e.uniCity,
                majorAllIds: "",
                majorAllEntities: []
              };
              this.schoolList.S.push(str);

              this.WriteType = "";
            });
          } else {
            var schoolId = this.VolunteerDetailsList.volunteerSchoolEntity;
            var S = [];
            schoolId.map(j => {
              S.push(parseInt(j.schoolId));
            });
            if (S.indexOf(parseInt(ID)) == -1) {
              var arrNew = [];
              arrNew.push(arr);
              arrNew.map(e => {
                var str = {
                  batch: e.batch,
                  logoUrl: e.logoUrl,
                  schoolId: e.schoolId,
                  schoolName: e.schoolName,
                  uniCity: e.uniCity,
                  majorAllIds: "",
                  majorAllEntities: []
                };
                this.schoolList.S.push(str);
                this.VolunteerDetailsList.volunteerSchoolEntity.push(str);
                this.WriteType = "";
              });
            } else {
              this.WriteType = "";
            }
          }
        } else {
          alert("不能超过" + this.Specialty.schoolNumber + "加学校");
        }
      }
      // if (
      //   this.Undergraduate.schoolNumber >
      //   this.VolunteerDetailsList.volunteerSchoolEntity.length
      // ) {
      //   var schoolId = this.VolunteerDetailsList.volunteerSchoolEntity;
      //   var S = [];
      //   schoolId.map(j => {
      //     S.push(parseInt(j.schoolId));
      //   });
      //   if (S.indexOf(parseInt(ID)) == -1) {
      //     var arrNew = [];
      //     arrNew.push(arr);
      //     arrNew.map(e => {
      //       var str = {
      //         batch: e.batch,
      //         logoUrl: e.logoUrl,
      //         schoolId: e.schoolId,
      //         schoolName: e.schoolName,
      //         uniCity: e.uniCity,
      //         majorAllEntities: []
      //       };
      //       this.VolunteerDetailsList.volunteerSchoolEntity.push(str);
      //       this.WriteType = "";
      //     });
      //   } else {
      //     this.WriteType = "";
      //   }
      // } else {
      //   alert("不能超过" + this.Undergraduate.schoolNumber);
      // }
    },

    addSchoolMajor(major, tiem, index, Index) {
      this.schoolMajorLists[index].majorAllEntities.push(major);

      this.MajorIdLIsts.push(parseInt(major.majorAllId));
    },

    cutSchoolMajor(id, index, Index) {
      var i = this.MajorIdLIsts.indexOf(parseInt(id));

      this.MajorIdLIsts.splice(i, 1);
      var arr = [];
      this.schoolMajorLists[index].majorAllEntities.map(t => {
        arr.push(parseInt(t.majorAllId));
      });
      var i2 = arr.indexOf(parseInt(id));
      this.schoolMajorLists[index].majorAllEntities.splice(i2, 1);
    },
     goshow(){
      // console.log(this.$route.params.schoolId)
      if(this.$route.params.schoolId== 'NaN'){
        this.toshow= 1 ;
      }else{
        this.toshow= 2 ;
      }
    }
  },
  beforeCreate() {
    this.$nextTick(() => {
      this.getBatch();
      this.goshow();
      
    });
  },
  watch:{
    $route(to, from) {
    //  console.log(this.$route.params.schoolId)
    console.log(to, from)
    }
  }
};
</script>
<style lang="scss" scoped>
.Write {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba($color: #000000, $alpha: 0.4);
  z-index: 1100;
  .Write_major {
    width: 480px;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    height: 550px;
    margin: 0 auto;
    margin-top: 30px;
    .schools_name {
      color: #757575;

      background: #f8f8f8;
      padding: 12px 18px;
    }
    .name_lists_header {
      padding-top: 34px;
      .Choose_Major {
        padding: 0 18px;
        display: flex;

        div {
          color: rgb(67, 149, 243);
          padding: 10px;
          font-size: 18px;
          margin-left: 52px;
          cursor: pointer;
        }
        span {
          font-size: 18px;
          padding: 12px 0;
        }
        i {
          color: #c8c8c8;
          font-size: 20px;
          padding: 12px 12px;
        }
      }
    }
    .name_lists_bottom {
      width: 100%;
      height: 100%;
      overflow: auto;
      padding-right: 50px;

      .lists_bottom {
        > p {
          text-align: center;
        }
        width: 200px;
        padding-bottom: 130px;
        > ul {
          li {
            display: block;
            width: 340%;
            display: flex;
            padding-left: 44px;
            padding-top: 26px;
            padding-bottom: 10px;
            border-bottom: 8px #f8f8f8 solid;
            .lists_bottom_left {
              width: 280px;
              h3 {
                line-height: 28px;
                padding-bottom: 14px;
              }

              .lists_bottom_left_bottom {
                display: flex;
                justify-content: space-between;
                flex-wrap: wrap-reverse;
                font-size: 10px;
                color: #757575;
                p {
                  line-height: 26px;
                  span {
                    color: #414141;
                  }
                }
              }
            }
            .school_list {
              display: flex;
              h3 {
                padding-top: 6px;
                h5 {
                  font-size: 12px;
                  color: #757575;
                }
              }
              img {
                display: block;
                width: 80px;
                height: 80px;
                margin-right: 20px;
              }
            }
          }
        }
      }
      .lists_bottom_new {
        padding-bottom: 200px;
        > ul {
          > li {
            padding: 20px;
            border-bottom: 8px solid #f8f8f8;
            .lists_new_header {
              border-bottom: 2px solid #ebeef5;
              padding-bottom: 10px;
              .header_school_new {
                display: flex;
                img {
                  width: 80px;
                  height: 80px;
                  display: block;
                  margin-right: 20px;
                }
                .header_school_new_right {
                  h3 {
                    padding-top: 6px;
                    line-height: 28px;
                    padding-bottom: 6px;
                  }
                  h4 {
                    font-size: 12px;
                    color: #757575;
                  }
                }
              }
              .meader_shool_new_numder {
                > ul {
                  font-size: 12px;
                  display: flex;
                  color: #757575;
                  margin-left: 10px;

                  flex-wrap: wrap-reverse;
                  li {
                    margin: 10px;
                    span {
                      color: #4f4f4f;
                    }
                  }
                }
              }
            }
            .lists_new_major {
              > ul {
                padding-top: 10px;
                > li {
                  margin: 10px 0;
                  .lists_new_majorName {
                    margin-bottom: 10px;
                    display: flex;
                    .icon-plus {
                      margin-right: 10px;
                      display: block;
                      width: 18px;
                      height: 18px;
                      border-radius: 50%;
                      border: 1px solid #757575;
                    }
                    i {
                      font-size: 24px;
                      margin-right: 10px;
                      display: block;
                    }
                    .el-icon-circle-check {
                      color: #4395f3;
                    }
                  }
                  .lists_new_majorNumder {
                    ul {
                      font-size: 12px;
                      display: flex;
                      color: #757575;
                      margin-left: 10px;
                      flex-wrap: wrap-reverse;
                      li {
                        margin: 5px 10px;
                        color: #4f4f4f;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
.VolunteerDetails {
  width: 100%;
  box-sizing: border-box;
}
.VolunteerDetails_boxtop {
  width: 1200px;
  margin: 0 auto;
  height: 68.6px;
}
.VolunteerDetails_top {
  height: 68.6px;
}
.VolunteerDetails_top_box {
  width: 170.6px;
  height: 68.6px;
}
.VolunteerDetails_top_logo {
  width: 50px;
  padding-top: 12.5px;
  margin-right: 24px;
}
.VolunteerDetails_top_content {
  display: inline;
  font-size: 22px;
  color: #515151;
  float: right;
  line-height: 68.6px;
}
.VolunteerDetails_bottom {
  width: 100%;
  background-color: #f6f6f6;
}
.VolunteerDetails_boxbottom {
  width: 1200px;
  margin: 0 auto;
}
.VolunteerDetails_bottom_option {
  padding-top: 27px;
  padding-bottom: 20px;
  span {
    color: #757575;
    font-size: 16px;
  }
}

.router-link-active {
  text-decoration: none;
}
.router{
   text-decoration: none;
}
.VolunteerDetails_bottom_form {
  height: 139px;
  background-color: #ffffff;
  position: relative;
  border-radius: 8px;
  margin-bottom: 48px;
}
.my_form {
  padding-top: 50px;
  margin-left: 73px;
  margin-bottom: 16px;
  color: #414141;
  font-weight: 550;
  font-size: 16px;
}
.my_time {
  margin-left: 73px;
  color: #414141;
  font-weight: 550;
  margin-bottom: 22px;
  font-size: 10px;
}
.my_input {
  position: absolute;
  top: 36px;
  left: 416px;
  width: 600px;
  color: #757575;
  line-height: 40px;
  display: flex;
  .el-input {
    width: 200px;
    margin-left: 20px;
  }
}
.my_lvse {
  height: 24px;
  background-color: #5fad62;
  color: #ffffff;
  border-radius: 6px;
}
.my_lvse_content {
  margin-left: 73px;
  line-height: 24px;
  font-size: 12px;
  font-weight: 550;
  .el-icon-arrow-right {
    color: #ffffff;
  }
}
.deit {
  font-size: 16px;
  position: absolute;
  right: 51px;
  top: 37px;
  border-radius: 8px;
}
.title_benke {
  margin-bottom: 35px;
  font-size: 17px;
  font-weight: 550;
  color: #414141;
}
.VolunteerDetails_bottom_benke {
}
.VolunteerDetails_bottom_benke_line {
  display: -webkit-flex; /* Safari */
  -webkit-flex-wrap: wrap; /* Safari 6.1+ */
  display: flex;
  flex-wrap: wrap;
  width: 1200px;
  justify-content: space-between;
}
.University {
  height: 283px;
  width: 270px;
  border-radius: 10px;
  background-color: #f0f0f0;
  margin-bottom: 44px;
  position: relative;
}
.University1 {
  height: 283px;
  width: 270px;
  border-radius: 10px;
  background-color: #f0f0f0;
  margin-bottom: 44px;
  border: 1px dashed #a9a9a9;
  position: relative;
  overflow: hidden;
  .add_school {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    margin: auto;
    background: rgba($color: #000000, $alpha: 0.4);
    .add_school_Tips {
      text-align: center;
      margin: 0 auto;

      margin-top: 60px;
      color: #fff;
    }
  }
}
.addschool {
  margin-top: 48px;
  text-align: center;
  font-size: 12px;
  color: #757575;
  margin-bottom: 36px;
}
.choose_school {
  margin-left: 43px;
  padding-left: 12px;
  width: 175px;
  padding-top: 15px;
  padding-bottom: 14px;
  margin-bottom: 26px;
  font-size: 13px;
  color: #757575;
  border: 1px dashed #757575;
  cursor: pointer;
}
.volunteer_add {
  margin-left: 43px;
  padding-left: 12px;
  width: 175px;
  padding-top: 15px;
  padding-bottom: 14px;
  font-size: 13px;
  color: #757575;
  border: 1px dashed #757575;
  cursor: pointer;
}
.span1 {
  color: #2e86ff;
}

.line_one {
  height: 20px;
  margin-top: 44px;
  margin-left: 32px;
  overflow: hidden;
  .el-icon-delete {
    position: absolute;
    top: 28px;
    right: 18px;
    color: #2e86ff;
  }
}
.school_logo {
  height: 20px;
  width: 20px;
  float: left;
  margin-right: 6px;
}
.school_name {
  float: left;
  line-height: 20px;
  font-size: 15px;
  color: #414141;
  font-weight: 550;
  margin-bottom: 9px;
}
.school_city {
  color: #c8c8c8;
  margin-left: 57px;
  font-size: 12px;
  margin-top: 10px;
  margin-bottom: 12px;
}
.major {
  margin-left: 57px;
  font-size: 12px;
  color: #757575;

  width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  justify-content: space-between;
  > span {
    padding: 6px 0;

    width: 118px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  i {
    color: #2e86ff;
    padding: 6px;
  }
}
.major1 {
  height: 0px;
  width: 270px;
}
.majorlan {
  position: absolute;
  color: #2e86ff;
  margin-left: 58px;
  font-size: 16px;
  bottom: 16px;
  cursor: pointer;
}
.el-icon-arrow-right {
  color: #2e86ff;
  font-size: 14px;
}

.VolunteerDetails_bottom_zhuanke {
}

.listindex {
  position: absolute;
  bottom: 16px;
  right: 26px;
  color: #757575;
}
.goSchool {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: 0 auto;
}
</style>